<?php

/**
 * KpiLogModel 模型
 * Class KpiLogModel
 */
class KpiLogModel extends BaseModel
{

    public $tableName = "kpi_log";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    static $typeText = [
        1   => '入账',
        2   => '出账'
    ];

    static $cateText = [
        1   => '奖励入账',
        2   => '提现减扣'
    ];

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'user_id'       => $data['user_id'],
                'type'          => $data['type'],
                'cate'          => $data['cate'],
                'point_before'  => $data['point_before'],
                'point'         => $data['point'],
                'point_after'   => $data['point_after'],
                'group_kpi'     => isset($data['group_kpi'])? $data['group_kpi']: 0,
                'ratio'         => $data['ratio'],
                'month_kpi'     => $data['month_kpi'],
                'ratio_month'   => $data['ratio_month'],
                'year_kpi'      => $data['year_kpi'],
                'ratio_year'    => $data['ratio_year'],
                'month_date'    => $data['month_date'],
                'withdraw_no'   => $data['withdraw_no'],
                'create_time'   => time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }


}